package com.sinothk.hussars.controller;


import com.sinothk.hussars.base.BaseController;
import com.sinothk.hussars.base.entity.PageReq;
import com.sinothk.hussars.entity.OrgEditVo;
import com.sinothk.hussars.entity.OrgManagerEntity;
import com.sinothk.hussars.entity.OrgAddVo;
import com.sinothk.hussars.service.OrgManagerService;
import com.sinothk.hussars.utils.XUtils;
import com.sinothk.server.support.annotation.callback.BizException;
import com.sinothk.server.support.annotation.callback.ResponseResult;
import com.sinothk.server.support.entity.PageData;
import com.sinothk.server.support.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 * 监管部门表 前端控制器
 * </p>
 *
 * @author liangyt
 * @since 2021-01-06
 */
@Api(tags = "机构_监管部门")
@RestController
@RequestMapping("/orgManager")
@ResponseResult()
public class OrgManagerController extends BaseController {

    private final OrgManagerService orgManagerService;

    public OrgManagerController(OrgManagerService orgManagerService) {
        this.orgManagerService = orgManagerService;
    }

    @ApiOperation(value = "新增：监管部门")
    @PostMapping("/save")
    public OrgManagerEntity save(@RequestBody OrgAddVo orgVo) {
        // 参数验证
//        if (StringUtil.isEmpty(orgVo.getOrgCode())) throw new BizException("部门编码不能为空");
        if (StringUtil.isEmpty(orgVo.getOrgName())) throw new BizException("部门名称不能为空");
        if (StringUtil.isEmpty(orgVo.getManagerAccount())) throw new BizException("管理员账号不能为空");
        if (StringUtil.isEmpty(orgVo.getManagerPwd())) throw new BizException("管理员密码不能为空");

        return orgManagerService.add(orgVo);
    }

    @ApiOperation(value = "查询：监管部门列表")
    @PostMapping("/orgPage")
    public PageData orgPage(@RequestBody PageReq<OrgManagerEntity> pageVo) {
        // 参数验证
        if (pageVo.getPageSize() == 0) pageVo.setPageSize(20);
        return orgManagerService.orgPage(pageVo);
    }

    @ApiOperation(value = "更新：监管部门")
    @PostMapping("/update")
    public OrgManagerEntity update(@RequestBody OrgEditVo orgVo) {
        // 参数验证
        if (StringUtil.isEmpty(orgVo.getId())) throw new BizException("部门Id不能为空");
        return orgManagerService.edit(orgVo);
    }
}

